<template>
	<view class="main">
		<!-- 消息 -->
		<view class="notice-item" v-if="id && !guid">
			<view class="title">{{info.Title}}</view>
			<view class="notice-item-head">
				<view class="notice-item-head-text">{{info.Creator | info.Sender}}</view>
				<view class="notice-item-head-date">发送时间: {{info.CreateDate | formatDate()}}</view>
			</view>
			<view class="notice-item-content">
				<view class="content">
					{{info.Content}}
					<view class="" v-if="info.Type == 'startapp'"><button type="primary" >进入系统</button></view>
				</view>
				
			</view>
		</view>
		<!-- 通知公告 -->
		<view class="notice-item" v-if="!id && guid">
			<view class="title">{{info.Title}}</view>
			<view class="notice-item-head">
				<view class="notice-item-head-text">{{info.Sender}}</view>
				<view class="notice-item-head-date">{{info.ModifyDate | formatDate()}}</view>
			</view>
			<view class="notice-item-content">
				<view class="content">
					<rich-text :nodes="decodeURIComponent(info.Content)"></rich-text>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script> 
	import {
		queryToDoList,updateStatus
	} from '@/common/services/ToDoWebSvr.js';
	
	export default {
		data() {
			return {
				id: '',
				guid: '',
				isloading: false,
				info: {
					Creator: "",
					Read: false,
					ModifyDate: new Date(),
					Receiver: "",
					Modifier: "",
					Title: "",
					Type: "",
					Content: "",
					Target: "",
					ValidState: 0,
					SourceSys: "",
					Id: "",
					ModifyReason: "",
					CreateDate: new Date()
				}
			};
		},
		created() {
			uni.showLoading({
				title: '',
				mask: true,
			});
			
		},
		onUnload() {
		  console.log('页面被卸载了，可能是返回操作导致的');
		  // 执行某些操作
		},
		onBackPress(options) {
			console.log(' onBackPress=====',options);
			// options.from 表示返回的来源
			if (options.from === 'backbutton') {
				console.log('物理返回键或导航栏的返回按钮被点击');
			} else if (options.from === 'navigateBack') {
				console.log(' uni.navigateBack 被调用');
			}
			// 返回 true 阻止默认返回行为，返回 false 或不返回则执行默认行为
			return true;
		},
		onLoad() {
			uni.setNavigationBarTitle({
					title: "消息内容"
			});
			
			this.id = uni.$func.urlParamHandle(document.baseURI || window.location.href,'id');
			this.guid = uni.$func.urlParamHandle(document.baseURI || window.location.href,'guid');
			if(!this.id && !this.guid){
				uni.showToast({
					title:'查询消息标识缺失！',
					duration:3500,
					icon:'none',
					success: (result) => {
						// uni.navigateBack({
						//     delta: 1
						// });
					},
				});
				setTimeout(function () {
					uni.hideLoading();
				}, 3000);
			}
			else{
				this.readNotifyPushInfo();
				this.readNotifyInfo();
			}
			
		},
		methods: {
			readNotifyPushInfo(){
				if(!this.id)return;
				readNotifyPush({token: uni.getStorageSync(setting.STORAGE_KEY+'token'), id: this.id},(res)=>{
					this.info = res;
					setTimeout(function () {
						uni.hideLoading();
					}, 100);
				});
			},
			readNotifyInfo(){
				if(!this.guid)return;
				getNotice({token: uni.getStorageSync(setting.STORAGE_KEY+'token'), guid: this.guid},(res)=>{
					this.info = res;
					setTimeout(function () {
						uni.hideLoading();
					}, 100);
				});
			},
			
			todecodeURIComponent(str){
				return decodeURIComponent(str);
			},
			
			
		},
		components: {},
	};
</script>

<style scoped lang="scss">
	.main {
		height: 100vh;
		overflow: scroll;
		background: #e9ebf8;
	}

	.title {
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
		padding: 40rpx 0 20rpx;
	}

	.notice-item {
		background-color: #fff;
		display: flex;
		flex-direction: column;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
		margin: 20rpx;

		&-head {
			display: flex;
			justify-content: space-between;
			align-items: flex-end;
			border-bottom: 2rpx solid #c6c6c6;
			padding: 16rpx;
			padding-bottom: 10rpx;

			&-text {
				font-size: 30rpx;
			}

			&-date {
				color: #A6A6A6;
				font-size: 24rpx;
			}
		}

		&-content {
			padding: 16rpx;

			.content {
				color: #959595;
				padding: 12px 8px;
				word-break: break-all;
			}
			
		
		}
	}
</style>